<template>
	<uni-transition mode-class="fade" :duration="200" :show="true">
		<view class="tabbar">
			<view ref='warpper' class="warpper">
				<view ref="navItem" class="navigator-item" v-for="(item,index) in (userType === 1 ? tabBar.siji_list : tabBar.list)" :key="item.pagePath"
					@click="switchTab(item,index)">
					<img :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
					<img :src="item.selectedIconPath" class="icon" v-else>
					<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
				</view>
			</view>
		</view>
	</uni-transition>

</template>

<script>
	export default {
		data() {
			return {
				userType: null,
				selectedIndex: uni.getStorageSync('selectedIndex') || 0,
				tabBar: {
					list: [{
							"pagePath": "pages/index/index",
							"iconPath": "/static/images/home.png",
							"selectedIconPath": "/static/images/home-active.png",
							"text": "首页"
						},
						 {
							"pagePath": "pages/my/my",
							"iconPath": "/static/images/my.png",
							"selectedIconPath": "/static/images/my-active.png",
							"text": "我的"
						}
					],
				},
			}
		},
		created() {
	
		},
		onLaunch() {
			this.selectedIndex = uni.getStorageSync('selectedIndex') || 0
		},
		methods: {
			switchTab(item, index) {
				console.log(item)
				let url = '/' + item.pagePath
				let pagePath = url
				uni.switchTab({
					url
				})
				this.tabBar.list.forEach((v, i) => {
					if (item.pagePath === v.pagePath) {
						uni.setStorageSync('selectedIndex', index);
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		height: 110rpx;
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		background-color: #fff;
		border-top: 1px solid #eee;
		box-sizing: border-box;

		.warpper {
			width: 100%;
			height: 100%;
			display: flex;
			align-items: center;

			.navigator-item {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
			}
		}

		.icon {
			width: 50rpx;
			height: 50rpx;
			margin-bottom: 5rpx;
		}
	}
</style>